
      
<h1 class="mume-header" id="go%E8%AF%AD%E8%A8%80%E6%9C%89%E4%BB%80%E4%B9%88%E4%B8%8D%E5%90%8C">Go&#x8BED;&#x8A00;&#x6709;&#x4EC0;&#x4E48;&#x4E0D;&#x540C;&#xFF1F;</h1>

<blockquote>
<p>Go&#x8BA9;&#x6211;&#x4F53;&#x9A8C;&#x5230;&#x4E86;&#x4ECE;&#x672A;&#x6709;&#x8FC7;&#x7684;<strong>&#x5F00;&#x53D1;&#x6548;&#x7387;</strong>&#x3002;<br>
--Go&#x4F5C;&#x8005;&#x4E4B;&#x4E00;&#xFF1A;&#x7F57;&#x5E03;&#xB7;&#x6D3E;&#x514B;(Rob Pike)</p>
</blockquote>
<p>&#x5F00;&#x53D1;&#x6548;&#x7387;&#xFF0C;&#x662F;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x65B0;&#x5165;&#x8FD9;&#x95E8;&#x5F00;&#x53D1;&#x8BED;&#x8A00;&#x6700;&#x76F4;&#x63A5;&#x7684;&#x611F;&#x53D7;&#x5C31;&#x662F;&#x8BED;&#x6CD5;&#x7B80;&#x6D01;&#x9AD8;&#x6548;&#xFF0C;&#x751A;&#x81F3;&#x6709;&#x4EBA;&#x7528;&#x201C;&#x9006;&#x5929;&#x201D;&#x4E24;&#x4E2A;&#x5B57;&#x6765;&#x5F62;&#x5BB9;&#x5B83;&#x7684;&#x8FD9;&#x4E00;&#x7279;&#x8272;&#x3002;&#x672C;&#x6587;&#x5C31;&#x629B;&#x5F00;&#x5176;&#x4ED6;&#xFF0C;&#x770B;&#x770B;Go&#x8BED;&#x8A00;&#x5012;&#x5E95;&#x6709;&#x4EC0;&#x4E48;&#x4E0D;&#x540C;&#xFF0C;&#x5B83;&#x5982;&#x4F55;&#x5E2E;&#x6211;&#x4EEC;&#x63D0;&#x9AD8;&#x5F00;&#x53D1;&#x6548;&#x7387;&#x3002;</p>
<h2 class="mume-header" id="%E4%B8%8D%E9%9C%80%E5%8A%A0%E5%88%86%E5%8F%B7">&#x4E0D;&#x9700;&#x52A0;&#x5206;&#x53F7;</h2>

<p>Go&#x8BED;&#x8A00;&#x4E0D;&#x9700;&#x8981;&#x5728;&#x8BED;&#x53E5;&#x6216;&#x8005;&#x58F0;&#x660E;&#x7684;&#x672B;&#x5C3E;&#x52A0;&#x5206;&#x53F7;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x4E3B;&#x52A8;&#x52A0;&#x5206;&#x53F7;&#x3002;&#x5C11;&#x5199;&#x4E00;&#x4E2A;&#x5B57;&#x662F;&#x4E00;&#x4E2A;&#x5B57; &#x1F603;&#x3002;<br>
&#x5982;&#x679C;&#x4F60;&#x559C;&#x6B22;&#x4E2A;&#x6027;&#x5316;&#x7684;&#x4EE3;&#x7801;&#x98CE;&#x683C;&#xFF0C;&#x9700;&#x8981;&#x53C2;&#x4E0E;&#x4E00;&#x4E0B;<a href="#%E5%85%B3%E4%BA%8E%E5%88%86%E5%8F%B7">&#x9644;&#x5F55;--&#x5173;&#x4E8E;&#x5206;&#x53F7;</a>&#x3002;</p>
<h2 class="mume-header" id="%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%B7%A5%E5%85%B7">&#x683C;&#x5F0F;&#x5316;&#x5DE5;&#x5177;</h2>

<p>Go&#x81EA;&#x5E26;&#x4E86;&#x683C;&#x5F0F;&#x5316;&#x5DE5;&#x5177;</p>
<ul>
<li>gofmt<br>
Go&#x8BED;&#x8A00;&#x5728;&#x4EE3;&#x7801;&#x683C;&#x5F0F;&#x5316;&#x4E0A;&#x6001;&#x5EA6;&#x5F88;&#x5F3A;&#x786C;&#x3002;gofmt&#x4F1A;&#x6309;&#x6807;&#x51C6;&#x683C;&#x5F0F;&#x5316;&#x4EE3;&#x7801;&#xFF0C;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x53C2;&#x6570;&#xFF0C;&#x4F60;&#x53EA;&#x80FD;&#x6309;&#x6807;&#x51C6;&#x8D70;&#x3002;&#x4F60;&#x4E0D;&#x7528;&#x64CD;&#x5FC3;&#x4EC0;&#x4E48;&#x6837;&#x7684;&#x4EE3;&#x7801;&#x98CE;&#x683C;&#x66F4;&#x597D;&#xFF0C;&#x6267;&#x884C;&#x6807;&#x51C6;&#x5C31;&#x884C;&#xFF0C;&#x7B80;&#x5355;&#x4E86;&#x5F88;&#x591A;&#xFF0C;&#x5C11;&#x4E86;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x6492;&#x903C;&#x3002;</li>
<li>goimports<br>
&#x6839;&#x636E;&#x9700;&#x8981;&#xFF0C;&#x81EA;&#x52A8;&#x6DFB;&#x52A0;&#x6216;&#x5220;&#x9664;import&#x58F0;&#x660E;&#x3002;&#x8FD9;&#x4E2A;&#x7701;&#x4E86;&#x4E0D;&#x5C11;&#x4E8B;&#x3002;<br>
&#x8FD9;&#x4E2A;&#x5DE5;&#x5177;&#x6CA1;&#x5305;&#x542B;&#x5728;&#x6807;&#x51C6;&#x5305;&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;<code>go get golang.org/x/tools/goimports</code></li>
</ul>
<blockquote>
<p>gofmt&#x548C;goimports&#x5728;&#x4E00;&#x4E9B;&#x5F00;&#x53D1;&#x5DE5;&#x5177;&#x4E2D;(vscode,idea...)&#x4F1A;&#x81EA;&#x52A8;&#x6267;&#x884C;&#xFF0C;&#x4F60;&#x518D;&#x4E5F;&#x4E0D;&#x9700;&#x8981;&#x82E6;&#x903C;&#x7684;&#x53BB;&#x624B;&#x52A8;&#x6267;&#x884C;&#x4E86;&#x3002;</p>
</blockquote>
<h2 class="mume-header" id="%E9%9A%90%E5%BC%8F%E5%88%9D%E5%A7%8B%E5%8C%96">&#x9690;&#x5F0F;&#x521D;&#x59CB;&#x5316;</h2>

<p>&#x5982;&#x679C;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x6CA1;&#x6709;&#x663E;&#x5F0F;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x5219;&#x88AB;&#x9690;&#x5F0F;&#x521D;&#x59CB;&#x5316;&#x4E3A;&#x53D8;&#x91CF;&#x7C7B;&#x578B;&#x7684;0&#x503C;&#x3002;</p>
<ul>
<li>&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x96F6;&#x503C;
<ul>
<li>&#x6570;&#x503C;&#xFF0C;0</li>
<li>&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&quot;&quot;</li>
<li>&#x5E03;&#x5C14;&#xFF0C;false</li>
<li>&#x63A5;&#x53E3;&#x6216;&#x5F15;&#x7528;&#x7C7B;&#x578B;, nil</li>
</ul>
</li>
</ul>
<blockquote>
<p>&#x4E0D;&#x9700;&#x8981;&#x64CD;&#x5FC3;undefined&#x4E86;</p>
</blockquote>
<h2 class="mume-header" id="%E8%87%AA%E5%A2%9E%E8%87%AA%E5%87%8F">&#x81EA;&#x589E;&amp;&#x81EA;&#x51CF;</h2>

<p>&#x548C;C&#x7CFB;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#x4E00;&#x6837;&#xFF0C;Go&#x4E5F;&#x6709;++&#x548C;--&#xFF0C;&#x4F46;&#x662F;Go&#x8BED;&#x8A00;&#x4E2D;<strong>&#x81EA;&#x589E;&#x81EA;&#x51CF;&#x662F;&#x8BED;&#x53E5;&#x4E0D;&#x662F;&#x8868;&#x8FBE;&#x5F0F;</strong>,&#x5E76;&#x4E14;++&#x548C;--&#x53EA;&#x80FD;&#x653E;&#x5728;&#x53D8;&#x91CF;&#x540E;&#x3002;&#x6240;&#x4EE5;&#x6CE8;&#x610F;&#x4EE5;&#x4E0B;&#x7528;&#x6CD5;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="go" class="language-go">  <span class="token comment">// &#x5408;&#x6CD5;  </span>
  i<span class="token operator">++</span>  
  i<span class="token operator">--</span>  

  <span class="token comment">// &#x975E;&#x6CD5;&#xFF0C;&#x81EA;&#x589E;&#x81EA;&#x51CF;&#x4E0D;&#x662F;&#x8868;&#x8FBE;&#x5F0F;  </span>
  j <span class="token operator">=</span> i<span class="token operator">++</span>  
  j <span class="token operator">=</span> i<span class="token operator">--</span>  

  <span class="token comment">// &#x975E;&#x6CD5;&#xFF0C;++&#x548C;--&#x53EA;&#x80FD;&#x653E;&#x5728;&#x53D8;&#x91CF;&#x540E;&#x9762;  </span>
  <span class="token operator">++</span>i  
  <span class="token operator">--</span>i  
</pre><p>&#x6211;&#x8BB0;&#x5F97;&#x66FE;&#x6709;&#x540C;&#x5B66;&#x5206;&#x4E0D;&#x6E05;C&#x8BED;&#x8A00;&#x4E2D;&#x7684;<code>++i</code>&#x548C;<code>i++</code>&#xFF0C;&#x53E6;&#x5916;&#xFF0C;&#x50CF;<code>j = ++i</code>&#x8FD9;&#x79CD;&#x7528;&#x6CD5;&#x66F4;&#x662F;&#x6270;&#x4E71;&#x89C6;&#x542C;&#x3002;&#x73B0;&#x5728;&#x597D;&#x4E86;&#xFF0C;&#x89E3;&#x653E;&#x4E86;&#xFF0C;&#x8001;&#x8001;&#x5B9E;&#x5B9E;&#x7528;&#x597D;<code>i++</code>&#x548C;<code>i--</code>&#x5C31;&#x591F;&#x4E86;</p>
<h2 class="mume-header" id="%E7%A9%BA%E6%A0%87%E8%AF%86%E7%AC%A6">&#x7A7A;&#x6807;&#x8BC6;&#x7B26;</h2>

<p>Go&#x8BED;&#x8A00;&#x4E0D;&#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x65E0;&#x7528;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x56E0;&#x6B64;&#x5C31;&#x6709;&#x4E86;&#x7A7A;&#x6807;&#x8BC6;&#x7B26;&#xFF0C;&#x5373;_&#xFF08;&#x4E0B;&#x5212;&#x7EBF;&#xFF09;&#x3002;<br>
&#x7A7A;&#x6807;&#x8BC6;&#x7B26;&#x591A;&#x7528;&#x5728;&#x63A5;&#x6536;&#x51FD;&#x6570;&#x591A;&#x8FD4;&#x56DE;&#x503C;&#x65F6;&#xFF0C;&#x5BF9;&#x4E0D;&#x9700;&#x8981;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x4F5C;&#x5360;&#x4F4D;&#x7528;&#x3002;</p>
<h2 class="mume-header" id="%E7%9F%AD%E5%8F%98%E9%87%8F%E5%A3%B0%E6%98%8E">&#x77ED;&#x53D8;&#x91CF;&#x58F0;&#x660E;</h2>

<p>&#x5728;&#x51FD;&#x6570;&#x5185;&#x53EF;&#x4EE5;&#x7528;<code>a:=3</code>&#x7684;&#x65B9;&#x5F0F;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x81EA;&#x52A8;&#x63A8;&#x7B97;&#x51FA;&#x53D8;&#x91CF;a&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;<br>
&#x7B80;&#x6D01;&#xFF0C;&#x4F46;&#x53EA;&#x80FD;&#x7528;&#x5728;&#x51FD;&#x6570;&#x5185;&#x3002;</p>
<blockquote>
<p>&#x7528;&#x8FC7;Pascal&#x7684;&#x540C;&#x5B66;&#x53EF;&#x80FD;&#x6CE8;&#x610F;&#x5230; <code>&apos;:=&apos;</code> &#x7684;&#x7528;&#x6CD5;&#xFF0C;&#x6CA1;&#x9519;&#xFF0C;Go&#x8BED;&#x8A00;&#x4E0D;&#x4F46;&#x7EE7;&#x627F;&#x4E86;C&#x7684;&#x5F88;&#x591A;&#x601D;&#x60F3;&#xFF0C;Go&#x7684;&#x53E6;&#x4E00;&#x652F;&#x7EE7;&#x627F;&#x5206;&#x652F;&#x5C31;&#x662F;Pascal</p>
</blockquote>
<h2 class="mume-header" id="%E5%A4%9A%E9%87%8D%E8%B5%8B%E5%80%BC">&#x591A;&#x91CD;&#x8D4B;&#x503C;</h2>

<p>Go&#x8BED;&#x8A00;&#x4E2D;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#x7528;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token comment">// &#x58F0;&#x660E;&#x53D8;&#x91CF;i&#x548C;j   &#x7ED3;&#x679C;&#xFF1A;&#x7C7B;&#x578B;&#x90FD;&#x662F;int&#xFF0C;i&#x7684;&#x503C;&#x662F;0&#xFF0C;j&#x7684;&#x503C;&#x662F;1  </span>
i<span class="token punctuation">,</span> j <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span>  

<span class="token comment">// &#x7ED9;i&#x548C;j&#x91CD;&#x65B0;&#x8D4B;&#x503C;  &#x7ED3;&#x679C;&#xFF1A;i&#x7684;&#x503C;&#x662F;2&#xFF0C;j&#x7684;&#x503C;&#x662F;3  </span>
i<span class="token punctuation">,</span> j <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span>  

<span class="token comment">// &#x91CD;&#x70B9;&#x6765;&#x4E86;&#xFF0C;&#x53D8;&#x91CF;&#x503C;&#x7684;&#x4EA4;&#x6362;  &#x7ED3;&#x679C;&#xFF1A;i&#x7684;&#x503C;&#x662F;3&#xFF0C;j&#x7684;&#x503C;&#x662F;2  </span>
i<span class="token punctuation">,</span> j <span class="token operator">=</span> j<span class="token punctuation">,</span> i  
<span class="token comment">// &#x5F53;&#x7136;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#xFF1A;</span>
a<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">,</span> a<span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">=</span> a<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">,</span> a<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
<span class="token comment">// &#x8FD8;&#x8BB0;&#x5F97;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#x4E2D;&#x901A;&#x8FC7;&#x4E34;&#x65F6;&#x53D8;&#x91CF;&#x6765;&#x4EA4;&#x6362;&#x6570;&#x636E;&#x5417;&#xFF1F;&#x4E0A;&#x9762;&#x7684;&#x7528;&#x6CD5;&#x4E0E;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#x76F8;&#x6BD4;&#xFF0C;&#x53EA;&#x80FD;&#x7528;&#x5E78;&#x798F;&#x6765;&#x5F62;&#x5BB9;:)  </span>
  

<span class="token comment">// &#x8BA1;&#x7B97;&#x6590;&#x6CE2;&#x7EB3;&#x5951;&#x6570;&#x636E;&#x7684;&#x7B2C;n&#x4E2A;&#x6570;&#xFF1A;</span>
<span class="token keyword">func</span> <span class="token function">gcd</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token builtin">int</span> <span class="token punctuation">{</span>
  <span class="token keyword">for</span> y <span class="token operator">!=</span> <span class="token number">0</span> <span class="token punctuation">{</span>
    x<span class="token punctuation">,</span> y <span class="token operator">=</span> y<span class="token punctuation">,</span> x<span class="token operator">%</span>y
  <span class="token punctuation">}</span>
  <span class="token keyword">return</span> x
<span class="token punctuation">}</span>

</pre><h2 class="mume-header" id="switch%E4%B8%8D%E9%9C%80%E8%A6%81break">switch&#x4E0D;&#x9700;&#x8981;break</h2>

<p>&#x4EE5;&#x524D;&#x5728;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#x4E2D;&#x4F7F;&#x7528;switch&#x603B;&#x662F;&#x5F88;&#x9EBB;&#x70E6;&#xFF0C;&#x6BCF;&#x4E2A;case&#x8BED;&#x53E5;&#x4E4B;&#x540E;&#x90FD;&#x8981;&#x52A0;break,Go&#x4E0D;&#x9700;&#x8981;&#xFF01;</p>
<ul>
<li>&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#x662F;&#x8FD9;&#x6837;</li>
</ul>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">switch</span><span class="token punctuation">(</span> foo <span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">case</span> <span class="token string">&quot;alpha&quot;</span><span class="token punctuation">:</span>
    <span class="token function">alpha</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">break</span><span class="token punctuation">;</span>
  <span class="token keyword">case</span> <span class="token string">&quot;beta&quot;</span><span class="token punctuation">:</span>
    <span class="token function">beta</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">break</span><span class="token punctuation">;</span>
  <span class="token keyword">default</span><span class="token punctuation">:</span>
    <span class="token comment">// something to default to</span>
    <span class="token keyword">break</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</pre><ul>
<li>Go&#x8BED;&#x8A00;&#x662F;&#x8FD9;&#x6837;</li>
</ul>
<pre data-role="codeBlock" data-info="Go" class="language-go"><span class="token keyword">switch</span> foo <span class="token punctuation">{</span>
  <span class="token keyword">case</span> <span class="token string">&quot;alpha&quot;</span><span class="token punctuation">:</span>
    <span class="token function">alpha</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token keyword">case</span> <span class="token string">&quot;beta&quot;</span><span class="token punctuation">:</span>
    <span class="token function">beta</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token keyword">default</span><span class="token punctuation">:</span>
    <span class="token comment">// something to default to</span>
<span class="token punctuation">}</span>
</pre><blockquote>
<p>Go&#x8BED;&#x8A00;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x60F3;&#x8981;&#x51E0;&#x4E2A;&#x76F8;&#x90BB;&#x7684;case&#x6267;&#x884C;&#x540C;&#x4E00;&#x6BB5;&#x903B;&#x8F91;&#xFF0C;&#x9700;&#x8981;&#x81EA;&#x5DF1;&#x663E;&#x5F0F;&#x7684;&#x52A0;&#x5165;fallthrough&#x8BED;&#x53E5;&#x3002;<br>
&#x50CF;&#x8FD9;&#x6837;&#x4E0D;&#x7528;break&#x624D;&#x5408;&#x7406;&#x561B;&#xFF0C;&#x6BD5;&#x7ADF;fallthrough&#x7684;&#x65B9;&#x5F0F;&#x5F88;&#x5C11;&#x7528;&#x5230;&#x3002;</p>
</blockquote>
<h2 class="mume-header" id="%E4%B8%8D%E9%9C%80%E8%A6%81public-private">&#x4E0D;&#x9700;&#x8981;Public&#x3001;Private</h2>

<p>Go&#x8BED;&#x8A00;&#x4E2D;&#xFF0C;&#x4EE5;<strong>&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x5F00;&#x5934;</strong>&#x7684;&#x53D8;&#x91CF;&#x3001;&#x51FD;&#x6570;&#x547D;&#x540D;&#x4F5C;&#x4E3A;&#x516C;&#x6709;&#x53D8;&#x91CF;&#xFF08;&#x6216;&#x51FD;&#x6570;&#xFF09;&#x5BFC;&#x51FA;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x5916;&#x90E8;&#x7684;&#x5305;&#x53EA;&#x80FD;&#x8BBF;&#x95EE;&#x4EE5;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x5F00;&#x5934;&#x7684;&#x53D8;&#x91CF;&#xFF08;&#x6216;&#x51FD;&#x6570;&#xFF09;&#x3002;&#x7ED3;&#x6784;&#x4F53;&#x6210;&#x5458;&#x547D;&#x540D;&#x4E5F;&#x9075;&#x5FAA;&#x6B64;&#x89C4;&#x5219;&#x3002;</p>
<h2 class="mume-header" id="%E5%87%8F%E5%B0%91%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2%E6%BD%9C%E8%A7%84%E5%88%99">&#x51CF;&#x5C11;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x6F5C;&#x89C4;&#x5219;</h2>

<h4 class="mume-header" id="%E7%B1%BB%E5%9E%8B%E4%B8%8D%E5%90%8C%E4%B8%8D%E8%83%BD%E8%BF%90%E7%AE%97">&#x7C7B;&#x578B;&#x4E0D;&#x540C;&#xFF0C;&#x4E0D;&#x80FD;&#x8FD0;&#x7B97;</h4>

<p>Go&#x8BED;&#x8A00;&#x4E2D;&#xFF0C;&#x5373;&#x4F7F;&#x662F;&#x57FA;&#x7840;&#x7C7B;&#x578B;&#x76F8;&#x540C;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x7C7B;&#x578B;&#x4E4B;&#x95F4;&#x4E5F;&#x4E0D;&#x80FD;&#x8FDB;&#x884C;&#x8FD0;&#x7B97;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token comment">// &#x5B9A;&#x4E49;&#x4E86;&#x4E24;&#x4E2A;&#x4E0D;&#x540C;&#x7C7B;&#x578B;Age&#x548C;Num&#xFF0C;&#x5176;&#x57FA;&#x7840;&#x7C7B;&#x578B;&#x90FD;&#x662F;int16</span>
<span class="token keyword">type</span> Age <span class="token builtin">int16</span>
<span class="token keyword">type</span> Num <span class="token builtin">int16</span>

<span class="token keyword">func</span> <span class="token function">typeTest</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">var</span> myAge Age <span class="token operator">=</span> <span class="token number">3</span>
  <span class="token keyword">var</span> aNum Num <span class="token operator">=</span> <span class="token number">4</span>
  
  <span class="token comment">// myAge&#x4E0E;aNum&#x7C7B;&#x578B;&#x4E0D;&#x540C;&#xFF0C;compile error: type mismatch</span>
  myAge <span class="token operator">=</span> aNum <span class="token operator">-</span> myAge
  
  <span class="token comment">// myAge&#x4E0E;aNum&#x7C7B;&#x578B;&#x4E0D;&#x540C;&#xFF0C;compile error: type mismatch</span>
  <span class="token keyword">if</span> myAge <span class="token operator">==</span> aNum <span class="token punctuation">{</span>
    fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;ok&quot;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</pre><p>&#x8981;&#x60F3;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x4E4B;&#x95F4;&#x8FD0;&#x7B97;&#x5FC5;&#x987B;&#x5F3A;&#x5236;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token keyword">type</span> Age <span class="token builtin">int16</span>
<span class="token keyword">type</span> Num <span class="token builtin">int16</span>

<span class="token keyword">func</span> <span class="token function">typeTest</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">var</span> myAge Age <span class="token operator">=</span> <span class="token number">3</span>
  <span class="token keyword">var</span> aNum Num <span class="token operator">=</span> <span class="token number">4</span>
  
  <span class="token comment">// &#x4F7F;&#x7528;Age(aNum)&#x8F6C;&#x6362;aNum</span>
  myAge <span class="token operator">=</span> <span class="token function">Age</span><span class="token punctuation">(</span>aNum<span class="token punctuation">)</span> <span class="token operator">-</span> myAge
  
  <span class="token comment">// &#x4F7F;&#x7528;Age(aNum)&#x8F6C;&#x6362;aNum</span>
  <span class="token keyword">if</span> myAge <span class="token operator">==</span> <span class="token function">Age</span><span class="token punctuation">(</span>aNum<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;ok&quot;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</pre><h4 class="mume-header" id="%E5%9F%BA%E7%A1%80%E7%B1%BB%E5%9E%8B%E4%B8%8D%E5%90%8C%E4%B8%8D%E8%83%BD%E8%BD%AC%E6%8D%A2">&#x57FA;&#x7840;&#x7C7B;&#x578B;&#x4E0D;&#x540C;&#xFF0C;&#x4E0D;&#x80FD;&#x8F6C;&#x6362;</h4>

<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token keyword">type</span> Age <span class="token builtin">int16</span>
<span class="token keyword">type</span> Num <span class="token builtin">int16</span>
<span class="token keyword">type</span> FType <span class="token builtin">float64</span>

<span class="token keyword">func</span> <span class="token function">typeTest</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">var</span> myAge Age <span class="token operator">=</span> <span class="token number">3</span>
  <span class="token keyword">var</span> aFloat FType <span class="token operator">=</span> <span class="token number">5.5</span>
  <span class="token keyword">var</span> sAge <span class="token operator">=</span> <span class="token string">&quot;6&quot;</span>

  <span class="token comment">// &#x53EF;&#x4EE5;&#x8F6C;&#x6362;&#xFF0C;&#x4F46;&#x4F1A;&#x5C06;float&#x622A;&#x65AD;&#xFF0C;&#x53EA;&#x4FDD;&#x7559;&#x6574;&#x6570;</span>
  myAge <span class="token operator">=</span> <span class="token function">Age</span><span class="token punctuation">(</span>aFloat<span class="token punctuation">)</span> <span class="token operator">-</span> myAge
  <span class="token comment">// &#x8F93;&#x51FA;&#x7ED3;&#x679C;&#xFF1A;2</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>myAge<span class="token punctuation">)</span>

  <span class="token comment">// &#x7F16;&#x8BD1;&#x9519;&#x8BEF;</span>
  myAge <span class="token operator">=</span> sAge
  <span class="token comment">// &#x7F16;&#x8BD1;&#x9519;&#x8BEF;</span>
  myAge <span class="token operator">=</span> <span class="token function">Age</span><span class="token punctuation">(</span>sAge<span class="token punctuation">)</span>

<span class="token punctuation">}</span>
</pre><p>Go&#x8BED;&#x8A00;&#x4E2D;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#x7684;&#x8F6C;&#x6362;&#x9700;&#x8981;<a href="https://www.cnblogs.com/heinoc/p/4106595.html">&#x4F7F;&#x7528;&#x8F6C;&#x6362;&#x51FD;&#x6570;</a></p>
<p>&#x4E0A;&#x9762;&#x4E24;&#x6761;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x76F8;&#x5173;&#x7684;&#x5185;&#x5BB9;&#x548C;&#x9AD8;&#x6548;&#x6709;&#x5173;&#x7CFB;&#x5417;&#xFF1F;<br>
&#x6709;&#xFF0C;&#x53D8;&#x91CF;&#x4F7F;&#x7528;&#x4E2D;&#x6CA1;&#x6709;&#x90A3;&#x4E48;&#x591A;&#x7684;&#x9690;&#x5F0F;&#x8F6C;&#x6362;&#xFF0C;&#x4E0D;&#x662F;&#x66F4;&#x76F4;&#x63A5;&#x9AD8;&#x6548;&#x5417;&#xFF1F;&#x5BF9;&#x4E8E;&#x6211;&#x8FD9;&#x79CD;&#x8BB0;&#x4E0D;&#x4F4F;&#x90A3;&#x4E48;&#x591A;&#x6F5C;&#x89C4;&#x5219;&#x7684;&#x61D2;&#x4EBA;&#x6765;&#x8BF4;&#x786E;&#x5B9E;&#x51CF;&#x8F7B;&#x4E86;&#x4E0D;&#x5C11;&#x5FC3;&#x667A;&#x538B;&#x529B;:)</p>
<h2 class="mume-header" id="%E5%B8%B8%E9%87%8F">&#x5E38;&#x91CF;</h2>

<ul>
<li>&#x4EE5;&#x7701;&#x7565;&#x65B9;&#x5F0F;&#x6279;&#x91CF;&#x521D;&#x59CB;&#x5316;&#x5E38;&#x91CF;</li>
</ul>
<pre data-role="codeBlock" data-info="Go" class="language-go"><span class="token comment">// &#x4E0B;&#x9762;&#x58F0;&#x660E;&#x4E86;5&#x4E2A;&#x5E38;&#x91CF;</span>
<span class="token keyword">const</span> <span class="token punctuation">(</span>
  a <span class="token operator">=</span> <span class="token number">1</span>
  b
  c
  d <span class="token operator">=</span> <span class="token number">2</span>
  e
<span class="token punctuation">)</span>

fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">,</span> d<span class="token punctuation">,</span> e<span class="token punctuation">)</span> <span class="token comment">//&quot;1 1 1 2  2&quot;</span>
</pre><ul>
<li>iota&#x5E38;&#x91CF;&#x751F;&#x6210;&#x5668;<br>
&#x5728;&#x6BCF;&#x4E00;&#x4E2A;const&#x5173;&#x952E;&#x5B57;&#x51FA;&#x73B0;&#x65F6;&#xFF0C;iota&#x88AB;&#x91CD;&#x7F6E;&#x4E3A;0,&#x6BCF;&#x51FA;&#x73B0;&#x4E00;&#x4E2A;&#x5E38;&#x91CF;&#x58F0;&#x660E;&#xFF0C;iota&#x81EA;&#x52A8;&#x52A0;1<pre data-role="codeBlock" data-info="Go" class="language-go">  <span class="token keyword">const</span> <span class="token punctuation">(</span>
    a <span class="token operator">=</span> <span class="token boolean">iota</span> <span class="token comment">// iota&#x91CD;&#x7F6E;&#x4E3A;0&#xFF0C;a&#x7B49;&#x4E8E;0</span>
    b <span class="token comment">// iota&#x81EA;&#x52A8;&#x52A0;1,b&#x7B49;&#x4E8E;1</span>
    c <span class="token comment">// iota&#x81EA;&#x52A8;&#x52A0;1,c&#x7B49;&#x4E8E;2</span>
  <span class="token punctuation">)</span>

  <span class="token keyword">const</span> <span class="token punctuation">(</span>
    d <span class="token operator">=</span> <span class="token boolean">iota</span> <span class="token comment">// iota&#x91CD;&#x7F6E;&#x4E3A;0&#xFF0C;d&#x7B49;&#x4E8E;0</span>
    e <span class="token comment">// iota&#x81EA;&#x52A8;&#x52A0;1,e&#x7B49;&#x4E8E;1</span>
  <span class="token punctuation">)</span>

  <span class="token keyword">const</span> f <span class="token operator">=</span> <span class="token boolean">iota</span> <span class="token comment">// iota&#x91CD;&#x7F6E;&#x4E3A;0&#xFF0C;f&#x7B49;&#x4E8E;0</span>
  <span class="token keyword">const</span> g <span class="token operator">=</span> <span class="token boolean">iota</span> <span class="token comment">// iota&#x91CD;&#x7F6E;&#x4E3A;0&#xFF0C;g&#x7B49;&#x4E8E;0</span>

  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">,</span> d<span class="token punctuation">,</span> e<span class="token punctuation">,</span> f<span class="token punctuation">,</span> g<span class="token punctuation">)</span> <span class="token comment">//&quot;0 1 2 0 1 0 0&quot;</span>
</pre></li>
<li>&#x7ED3;&#x5408;&#x4EE5;&#x4E0A;&#x4E24;&#x79CD;&#x8BED;&#x6CD5;<pre data-role="codeBlock" data-info="Go" class="language-go">  <span class="token keyword">const</span> <span class="token punctuation">(</span>
    a <span class="token operator">=</span> <span class="token boolean">iota</span> <span class="token comment">// iota&#x91CD;&#x7F6E;&#x4E3A;0&#xFF0C;a&#x7B49;&#x4E8E;0</span>
    b        <span class="token comment">// iota&#x81EA;&#x589E;,b&#x7B49;&#x4E8E;1</span>
    c <span class="token operator">=</span> <span class="token string">&quot;hh&quot;</span> <span class="token comment">// c&#x7B49;&#x4E8E;&#x201C;hh&#x201D;,iota&#x4F9D;&#x7136;&#x81EA;&#x589E;&#xFF0C;&#x7B49;&#x4E8E;2</span>
    d        <span class="token comment">// d&#x7B49;&#x4E8E;&#x201C;hh&#x201D;,iota&#x4F9D;&#x7136;&#x81EA;&#x589E;&#xFF0C;&#x7B49;&#x4E8E;3</span>
    e <span class="token operator">=</span> <span class="token boolean">iota</span> <span class="token comment">// &#x6062;&#x590D;iota, iota&#x81EA;&#x589E;&#xFF0C;e&#x7B49;&#x4E8E;4</span>
    f        <span class="token comment">// iota&#x81EA;&#x589E;,f&#x7B49;&#x4E8E;5</span>
    g        <span class="token comment">// iota&#x81EA;&#x589E;,f&#x7B49;&#x4E8E;6</span>
  <span class="token punctuation">)</span>

  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">,</span> d<span class="token punctuation">,</span> e<span class="token punctuation">,</span> f<span class="token punctuation">,</span> g<span class="token punctuation">)</span> <span class="token comment">//0 1 hh hh 4 5 6</span>

  <span class="token keyword">const</span> <span class="token punctuation">(</span>
    <span class="token boolean">_</span> <span class="token operator">=</span> <span class="token number">1</span> <span class="token operator">&lt;&lt;</span> <span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">*</span> <span class="token boolean">iota</span><span class="token punctuation">)</span> <span class="token comment">// 1&#x5DE6;&#x79FB;&#xFF08;10*0&#xFF09;&#x4F4D;&#xFF0C;&#x8FD8;&#x662F;1</span>
    KB <span class="token comment">// 1&#x5DE6;&#x79FB;&#xFF08;10*1&#xFF09;&#x4F4D;&#xFF0C;1024</span>
    MB <span class="token comment">// 1&#x5DE6;&#x79FB;&#xFF08;10*2&#xFF09;&#x4F4D;&#xFF0C;1048576</span>
    GB <span class="token comment">// 1&#x5DE6;&#x79FB;&#xFF08;10*3&#xFF09;&#x4F4D;&#xFF0C;1073741824</span>
    TB <span class="token comment">// 1&#x5DE6;&#x79FB;&#xFF08;10*4&#xFF09;&#x4F4D;&#xFF0C;1099511627776</span>
    PB <span class="token comment">// 1&#x5DE6;&#x79FB;&#xFF08;10*5&#xFF09;&#x4F4D;&#xFF0C;11125899906842624</span>
    EB <span class="token comment">// 1&#x5DE6;&#x79FB;&#xFF08;10*6&#xFF09;&#x4F4D;&#xFF0C;1152921504606846976</span>
    ZB <span class="token comment">// 1&#x5DE6;&#x79FB;&#xFF08;10*7&#xFF09;&#x4F4D;&#xFF0C;1180591620717411303424</span>
    YB <span class="token comment">// 1&#x5DE6;&#x79FB;&#xFF08;10*8&#xFF09;&#x4F4D;&#xFF0C;1208925819614629174706176</span>
  <span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>KB<span class="token punctuation">,</span> MB<span class="token punctuation">,</span> GB<span class="token punctuation">,</span> TB<span class="token punctuation">,</span> PB<span class="token punctuation">,</span> EB<span class="token punctuation">,</span> <span class="token punctuation">(</span>ZB <span class="token operator">/</span> EB<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span>YB <span class="token operator">/</span> EB<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token comment">// &#x4E0A;&#x9762;&#x8F93;&#x51FA;1024 1048576 1073741824 1099511627776 1125899906842624 1152921504606846976 1024 1048576</span>
  <span class="token comment">// &#x6CE8;&#x610F;&#xFF1A;ZB&#x548C;YB&#x5DF2;&#x7ECF;&#x8D85;&#x51FA;&#x4E86;int&#x6240;&#x80FD;&#x8868;&#x8FBE;&#x7684;&#x6700;&#x5927;&#x6570;&#xFF0C;&#x5728;Go&#x8BED;&#x8A00;&#x4E2D;&#x5B83;&#x4EEC;&#x4F9D;&#x7136;&#x53EF;&#x4EE5;&#x53C2;&#x4E0E;&#x8FD0;&#x7B97;&#xFF0C;&#x4F46;&#x4E0D;&#x80FD;&#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;&#xFF0C;&#x56E0;&#x4E3A;&#x8D85;&#x51FA;&#x4E86;&#x53D8;&#x91CF;&#x8303;&#x56F4;</span>
  
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>ZB<span class="token punctuation">)</span> <span class="token comment">// compile error:overflows int</span>
</pre>Go&#x8BED;&#x8A00;&#x4E2D;&#x6CA1;&#x6709;&#x679A;&#x4E3E;&#xFF0C;&#x8FD9;&#x5C31;&#x662F;&#x679A;&#x4E3E;&#x3002;&#x53C8;&#x6709;&#x4E00;&#x4E2A;&#x6982;&#x5FF5;&#x4E0D;&#x7528;&#x5B66;&#x4E86;&#xFF0C;haha...</li>
</ul>
<h2 class="mume-header" id="slice%E5%88%87%E7%89%87">Slice&#xFF08;&#x5207;&#x7247;&#xFF09;</h2>

<p>&#x5207;&#x7247;&#x5207;&#x7247;&#xFF0C;&#x628A;&#x6570;&#x7EC4;&#x5207;&#x6210;&#x7247;&#x6765;&#x7528;:),&#x501F;&#x7528;&#x201C;Go&#x8BED;&#x8A00;&#x5723;&#x7ECF;&#x201D;&#x4E2D;&#x7684;&#x56FE;&#x6765;&#x8BF4;&#x660E;&#xFF1A;<br>
<img src="/images/slice.png" alt="Slice"><br>
&#x56FE;&#x4E2D;<strong>&#x5207;&#x7247;Q2</strong>&#x662F;&#x4E00;&#x4E2A;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#xFF0C;&#x5F15;&#x7528;&#x4E86;&#x6570;&#x7EC4;months&#x4E2D;index&#x4E3A;4&#x3001;5&#x3001;6&#x7684;&#x4E09;&#x4E2A;&#x5143;&#x7D20;&#x4F9B;&#x81EA;&#x5DF1;&#x4F7F;&#x7528;</p>
<h2 class="mume-header" id="defer">defer</h2>

<p>&#x5728;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x51FD;&#x6570;&#x524D;&#x52A0;&#x4E0A;defer&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x4F1A;&#x88AB;&#x5EF6;&#x8FDF;&#x6267;&#x884C;&#x3002;defer&#x540E;&#x7684;&#x51FD;&#x6570;&#x76F4;&#x5230;&#x5305;&#x542B;&#x8BE5;defer&#x8BED;&#x53E5;&#x7684;&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x65F6;&#xFF0C;&#x624D;&#x4F1A;&#x88AB;&#x6267;&#x884C;&#x3002;</p>
<ul>
<li>&#x5176;&#x5B83;&#x8BED;&#x8A00;&#x4E2D;&#x8BFB;&#x5199;&#x6587;&#x4EF6;&#xFF1A;</li>
</ul>
<pre data-role="codeBlock" data-info="CSharp" class="language-csharp"><span class="token keyword">void</span> <span class="token function">writeTxt</span><span class="token punctuation">(</span><span class="token keyword">string</span> msg<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
  <span class="token class-name">FileStream</span> fs <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
  <span class="token keyword">try</span>
  <span class="token punctuation">{</span>
      fs <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileStream</span><span class="token punctuation">(</span>filename<span class="token punctuation">,</span> FileMode<span class="token punctuation">.</span>Create<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token comment">// &#x6587;&#x4EF6;&#x64CD;&#x4F5C;...</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">catch</span><span class="token punctuation">(</span><span class="token class-name">Exception</span> ex<span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
      <span class="token comment">// &#x5904;&#x7406;&#x5F02;&#x5E38;</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">finally</span>
  <span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>fs <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
      fs<span class="token punctuation">.</span><span class="token function">Close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</pre><ul>
<li>&#x5728;Go&#x8BED;&#x8A00;&#x4E2D;&#x5229;&#x7528;defer&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;</li>
</ul>
<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token keyword">func</span> <span class="token function">writeTxt</span><span class="token punctuation">(</span>msg st<span class="token punctuation">)</span><span class="token punctuation">{</span>
  file1<span class="token punctuation">,</span> err <span class="token operator">:=</span> os<span class="token punctuation">.</span><span class="token function">Create</span><span class="token punctuation">(</span><span class="token string">&quot;test.txt&quot;</span><span class="token punctuation">)</span>
  <span class="token keyword">defer</span> file1<span class="token punctuation">.</span><span class="token function">Close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

  <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x5904;&#x7406;&#x9519;&#x8BEF;&#x3002;&#x3002;&#x3002;</span>
  <span class="token punctuation">}</span>
  <span class="token comment">// &#x6587;&#x4EF6;&#x64CD;&#x4F5C;...</span>
<span class="token punctuation">}</span>
</pre><p>&#x8FD9;&#x6837;&#x7B80;&#x6D01;&#x591A;&#x4E86;&#x5427;&#x3002;&#x6253;&#x5F00;&#x6587;&#x4EF6;&#x540E;&#x9A6C;&#x4E0A;&#x5199;&#x5173;&#x95ED;&#x8BED;&#x53E5;&#xFF0C;&#x66F4;&#x52A0;&#x6E05;&#x6670;&#x660E;&#x4E86;&#xFF0C;&#x4E5F;&#x6CBB;&#x6108;&#x4E86;&#x6211;&#x90A3;&#x4E22;&#x4E09;&#x843D;&#x56DB;&#x7684;&#x574F;&#x6BDB;&#x75C5;:)</p>
<h2 class="mume-header" id="%E5%A4%9A%E8%BF%94%E5%9B%9E%E5%80%BC">&#x591A;&#x8FD4;&#x56DE;&#x503C;</h2>

<p>&#x7528;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#x6709;&#x53EF;&#x80FD;&#x4F1A;&#x5199;&#x51FA;&#x7C7B;&#x4F3C;&#x8FD9;&#x6837;&#x7684;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="CSharp" class="language-csharp"><span class="token comment">// &#x51FD;&#x6570;&#x5B9A;&#x4E49;&#xFF0C;&#x9664;&#x4E86;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;bool&#x503C;&#x5916;&#xFF0C;&#x901A;&#x8FC7;&#x5F15;&#x7528;&#x7C7B;&#x578B;string&#x6765;&#x63D0;&#x4F9B;&#x66F4;&#x53CB;&#x597D;&#x7684;&#x9519;&#x8BEF;&#x8FD4;&#x56DE;&#x4FE1;&#x606F;</span>
<span class="token keyword">public</span> <span class="token keyword">bool</span> <span class="token function">Connected</span><span class="token punctuation">(</span><span class="token keyword">string</span> localpath<span class="token punctuation">,</span> <span class="token keyword">ref</span> <span class="token keyword">string</span> errMsg<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token comment">// ....</span>
    <span class="token keyword">return</span> connected<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</pre><pre data-role="codeBlock" data-info="CSharp" class="language-csharp"><span class="token comment">// &#x51FD;&#x6570;&#x8C03;&#x7528;</span>
<span class="token keyword">string</span> err <span class="token operator">=</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token function">Connected</span><span class="token punctuation">(</span>localPath<span class="token punctuation">,</span> <span class="token keyword">ref</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>String<span class="token punctuation">.</span><span class="token function">IsNullOrEmpty</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
      <span class="token comment">// &#x5EFA;&#x7ACB;&#x65B0;&#x8FDE;&#x63A5;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">else</span>
    <span class="token punctuation">{</span>
      <span class="token comment">// &#x9519;&#x8BEF;&#x5904;&#x7406;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token comment">// &#x6B63;&#x5E38;&#x4E1A;&#x52A1;&#x5904;&#x7406;......</span>
</pre><p>&#x603B;&#x611F;&#x89C9;&#xFF0C;&#x7528;&#x53C2;&#x6570;&#x4F5C;&#x8FD4;&#x56DE;&#x503C;&#x8FD9;&#x79CD;&#x4E8B;&#xFF0C;1.&#x9EBB;&#x70E6;&#xFF0C;2.&#x4E0D;&#x6B63;&#x89C4;&#x3002;<br>
&#x73B0;&#x5728;&#x597D;&#x4E86;&#xFF0C;Go&#x8BED;&#x8A00;&#x7684;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x63D0;&#x4F9B;&#x591A;&#x4E2A;&#x8FD4;&#x56DE;&#x503C;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token comment">// &#x51FD;&#x6570;&#x5B9A;&#x4E49;</span>
<span class="token keyword">func</span> <span class="token function">Connected</span><span class="token punctuation">(</span>localPath <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">bool</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token comment">//......</span>
  <span class="token keyword">return</span> connected<span class="token punctuation">,</span> <span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</pre><pre data-role="codeBlock" data-info="go" class="language-go"><span class="token comment">// &#x51FD;&#x6570;&#x8C03;&#x7528;  </span>
isConnected<span class="token punctuation">,</span> err <span class="token operator">:=</span> <span class="token function">Connected</span><span class="token punctuation">(</span>path<span class="token punctuation">)</span> 
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
  <span class="token comment">// &#x9519;&#x8BEF;&#x5904;&#x7406;</span>
<span class="token punctuation">}</span>
<span class="token keyword">if</span> <span class="token operator">!</span>isConnected <span class="token punctuation">{</span>
  <span class="token comment">// &#x5EFA;&#x7ACB;&#x65B0;&#x8FDE;&#x63A5;</span>
<span class="token punctuation">}</span>
<span class="token comment">// &#x6B63;&#x5E38;&#x4E1A;&#x52A1;&#x5904;&#x7406;......</span>
</pre><p>Go&#x8BED;&#x8A00;&#x4E2D;&#x5E38;&#x89C4;&#x9519;&#x8BEF;&#x5904;&#x7406;&#x90FD;&#x662F;&#x8FD9;&#x4E48;&#x505A;&#x7684;&#xFF0C;&#x201C;&#x4E0D;&#x6B63;&#x89C4;&#x201D;&#x7684;&#x5FC3;&#x7406;&#x5305;&#x88B1;&#x53EF;&#x4EE5;&#x653E;&#x4E0B;&#x4E86;&#xFF0C;&#x800C;&#x4E14;&#xFF0C;&#x76F8;&#x6BD4;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#xFF0C;&#x76F8;&#x540C;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x5176;&#x5B9E;&#x73B0;&#x4EE3;&#x7801;&#x5374;&#x66F4;&#x7B80;&#x5355;&#x6E05;&#x6670;&#x4E86;:)</p>
<h2 class="mume-header" id="%E6%B2%A1%E6%9C%89%E7%B1%BB">&#x6CA1;&#x6709;&#x7C7B;</h2>

<p>&#x7C7B;&#xFF1F;&#x6CA1;&#x6709;&#x7C7B;&#xFF0C;Go&#x8BED;&#x8A00;&#x91CC;&#x6CA1;&#x6709;&#x7C7B;&#xFF01;<br>
&#x6CA1;&#x6709;&#x7C7B;&#x5982;&#x4F55;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#xFF1F;&#xFF01;<br>
&#x5982;&#x679C;&#x6709;C++&#x7ECF;&#x9A8C;&#x7684;&#x540C;&#x5B66;&#x5E94;&#x8BE5;&#x8BB0;&#x5F97;&#x8FD9;&#x6837;&#x4E00;&#x4E2A;&#x6982;&#x5FF5;&#x201C;&#x7C7B;&#x7684;&#x672C;&#x8D28;&#x5C31;&#x662F;&#x7ED3;&#x6784;&#x4F53;&#x201D;&#xFF0C;Go&#x8BED;&#x8A00;&#x5C31;&#x662F;&#x4ECE;&#x672C;&#x8D28;&#x51FA;&#x53D1;&#x3002;</p>
<ul>
<li>&#x7ED3;&#x6784;&#x4F53;<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token comment">// &#x8FD9;&#x91CC;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x7ED3;&#x6784;&#x4F53;</span>
<span class="token keyword">type</span> Point <span class="token keyword">struct</span><span class="token punctuation">{</span> X<span class="token punctuation">,</span> Y <span class="token builtin">float64</span> <span class="token punctuation">}</span>

<span class="token comment">// &#x8FD9;&#x91CC;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x51FD;&#x6570;</span>
<span class="token keyword">func</span> <span class="token function">Distance</span><span class="token punctuation">(</span>p<span class="token punctuation">,</span> q Point<span class="token punctuation">)</span> <span class="token builtin">float64</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> math<span class="token punctuation">.</span><span class="token function">Hypot</span><span class="token punctuation">(</span>q<span class="token punctuation">.</span>X<span class="token operator">-</span>p<span class="token punctuation">.</span>X<span class="token punctuation">,</span> q<span class="token punctuation">.</span>Y<span class="token operator">-</span>p<span class="token punctuation">.</span>Y<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</pre>&#x5B9A;&#x4E49;&#x65B9;&#x6CD5;&#xFF1A;<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token comment">// &#x6211;&#x4EEC;&#x5728;&#x51FD;&#x6570;&#x524D;&#x9762;&#x52A0;&#x4E00;&#x4E2A;&#x62EC;&#x53F7;&#xFF0C;&#x91CC;&#x9762;&#x653E;&#x5165;`p Point`,&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x5C31;&#x53D8;&#x6210;&#x4E86;Point&#x7684;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>p Point<span class="token punctuation">)</span> <span class="token function">Distance</span><span class="token punctuation">(</span>q Point<span class="token punctuation">)</span> <span class="token builtin">float64</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> math<span class="token punctuation">.</span><span class="token function">Hypot</span><span class="token punctuation">(</span>q<span class="token punctuation">.</span>X<span class="token operator">-</span>p<span class="token punctuation">.</span>X<span class="token punctuation">,</span> q<span class="token punctuation">.</span>Y<span class="token operator">-</span>p<span class="token punctuation">.</span>Y<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token comment">// &#x65B9;&#x6CD5;&#x7684;&#x8C03;&#x7528; </span>
p1 <span class="token operator">:=</span> Point<span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">}</span>
p1<span class="token punctuation">.</span><span class="token function">Distance</span><span class="token punctuation">(</span>Point<span class="token punctuation">{</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</pre>&#x7ED3;&#x6784;&#x4F53;&#x6210;&#x5458;&#xFF08;&#x5BFC;&#x51FA;/&#x975E;&#x5BFC;&#x51FA;&#xFF09;+&#x65B9;&#x6CD5;&#xFF08;&#x5BFC;&#x51FA;/&#x975E;&#x5BFC;&#x51FA;&#xFF09;&#x5F62;&#x6210;&#x4E86;<strong>&#x5C01;&#x88C5;</strong>&#x3002;
<ul>
<li>&#x7ED3;&#x6784;&#x4F53;&#x5D4C;&#x5957;</li>
</ul>
<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token keyword">type</span> Point <span class="token keyword">struct</span> <span class="token punctuation">{</span>
  X<span class="token punctuation">,</span> Y <span class="token builtin">int</span>
<span class="token punctuation">}</span>
<span class="token keyword">type</span> Circle <span class="token keyword">struct</span> <span class="token punctuation">{</span>
  Center Point
  Radius <span class="token builtin">int</span>
<span class="token punctuation">}</span>
</pre>&#x5728;&#x8FD9;&#x6837;&#x7684;&#x7ED3;&#x6784;&#x4F53;&#x5D4C;&#x5957;&#x4E2D;&#xFF0C;&#x5916;&#x5C42;&#x7684;&#x7ED3;&#x6784;&#x4F53;&#x4E0D;&#x4EC5;&#x4EC5;&#x662F;&#x83B7;&#x5F97;&#x4E86;&#x5185;&#x5C42;&#x7ED3;&#x6784;&#x4F53;&#x7684;&#x6240;&#x6709;&#x6210;&#x5458;&#xFF0C;&#x800C;&#x4E14;&#x4E5F;&#x83B7;&#x5F97;&#x4E86;&#x5168;&#x90E8;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x662F;Go&#x8BED;&#x8A00;&#x5BF9;&#x9762;&#x5411;&#x5BF9;&#x8C61;<strong>&#x7EE7;&#x627F;</strong>&#x7279;&#x6027;&#x5B9E;&#x73B0;&#x3002;</li>
<li>&#x7C7B;&#x578B;<br>
&#x90A3;&#x4E48;Go&#x8BED;&#x8A00;&#x4E2D;&#x7ED3;&#x6784;&#x4F53;&#x5C31;&#x76F8;&#x5F53;&#x4E8E;&#x7C7B;&#xFF1F;<br>
&#x4E5F;&#x4E0D;&#x5C3D;&#x7136;&#xFF0C;&#x7EC6;&#x5FC3;&#x7684;&#x540C;&#x5B66;&#x53EF;&#x80FD;&#x53D1;&#x73B0;&#x4E86;&#xFF0C;&#x5B9A;&#x4E49;&#x7ED3;&#x6784;&#x4F53;&#x65F6;&#x7528;&#x4E86;<code>type</code>&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x5176;&#x5B9E;&#x901A;&#x8FC7;<code>type</code>&#x5B9A;&#x4E49;&#x7684;&#x7C7B;&#x578B;&#x90FD;&#x53EF;&#x4EE5;&#x6709;&#x65B9;&#x6CD5;&#x3002;</li>
</ul>
<h2 class="mume-header" id="%E6%8E%A5%E5%8F%A3">&#x63A5;&#x53E3;</h2>

<p>&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x8FD8;&#x6709;<strong>&#x591A;&#x6001;</strong>&#xFF0C;&#x54B1;&#x4EEC;&#x901A;&#x8FC7;&#x63A5;&#x53E3;&#x6765;&#x4F53;&#x73B0;&#x3002;</p>
<h4 class="mume-header" id="%E7%94%A8%E6%B3%95">&#x7528;&#x6CD5;</h4>

<p>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token keyword">type</span> Namer <span class="token keyword">interface</span> <span class="token punctuation">{</span>
  <span class="token function">SetName</span><span class="token punctuation">(</span>name <span class="token builtin">string</span><span class="token punctuation">)</span> 
  <span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span>
<span class="token punctuation">}</span>
</pre><p>&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token keyword">type</span> Dog <span class="token keyword">struct</span> <span class="token punctuation">{</span>
  dogName <span class="token builtin">string</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>dog Dog<span class="token punctuation">)</span> <span class="token function">Run</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// ......</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;SetName&#x65B9;&#x6CD5;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>dog <span class="token operator">*</span>Dog<span class="token punctuation">)</span> <span class="token function">SetName</span><span class="token punctuation">(</span>name <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	dog<span class="token punctuation">.</span>dogName <span class="token operator">=</span> name
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;GetName&#x65B9;&#x6CD5;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>dog <span class="token operator">*</span>Dog<span class="token punctuation">)</span> <span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> dog<span class="token punctuation">.</span>dogName
<span class="token punctuation">}</span>
</pre><h4 class="mume-header" id="%E4%BC%98%E7%82%B9">&#x4F18;&#x70B9;</h4>

<ul>
<li>&#x5B9E;&#x73B0;&#x7B80;&#x5355;<br>
&#x4E0A;&#x9762;Dog&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x4E86;&#x4E09;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x5176;&#x4E2D;SetName&#x548C;GetName&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x548C;&#x63A5;&#x53E3;Namer&#x4E2D;&#x58F0;&#x660E;&#x7684;&#x65B9;&#x6CD5;&#x5B8C;&#x5168;&#x76F8;&#x540C;&#xFF0C;&#x8FD9;&#x5C31;&#x76F8;&#x5F53;&#x4E8E;Dog&#x7C7B;&#x578B;&#x5B9E;&#x73B0;&#x4E86;Namer&#x63A5;&#x53E3;&#x3002;&#x4E0D;&#x9700;&#x8981;&#x50CF;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#x4E2D;&#x7528;&#x7C7B;&#x4F3C;<code>class Dog: Namer</code>&#x8BED;&#x6CD5;&#x6765;&#x663E;&#x5F0F;&#x7684;&#x58F0;&#x660E;&#x5F53;&#x524D;&#x7C7B;&#x5B9E;&#x73B0;&#x4E86;&#x54EA;&#x4E2A;&#x63A5;&#x53E3;&#x3002;</li>
<li>&#x6240;&#x6709;&#x81EA;&#x5B9A;&#x4E49;&#x7C7B;&#x578B;&#x90FD;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;<br>
&#x4E0D;&#x50CF;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#xFF0C;&#x63A5;&#x53E3;&#x7684;&#x5B9E;&#x73B0;&#x53EA;&#x80FD;&#x901A;&#x8FC7;&#x7C7B;&#x3002;Go&#x8BED;&#x8A00;&#x4E2D;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#xFF1A;<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token keyword">type</span> Dog <span class="token builtin">string</span>

<span class="token comment">// &#x5B9E;&#x73B0;SetName&#x65B9;&#x6CD5;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>dog <span class="token operator">*</span>Dog<span class="token punctuation">)</span> <span class="token function">SetName</span><span class="token punctuation">(</span>name <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token operator">*</span>dog <span class="token operator">=</span> <span class="token function">Dog</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;GetName&#x65B9;&#x6CD5;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>dog <span class="token operator">*</span>Dog<span class="token punctuation">)</span> <span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token function">string</span><span class="token punctuation">(</span><span class="token operator">*</span>dog<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</pre><h2>Goroutines</h2>
Go&#x8BED;&#x8A00;&#x662F;&#x4E3A;&#x6570;&#x4E0D;&#x591A;&#x7684;&#x51E0;&#x4E2A;&#x539F;&#x751F;&#x5B9E;&#x73B0;&#x5E76;&#x53D1;&#x7684;&#x8BED;&#x8A00;&#x4E4B;&#x4E00;&#xFF0C;&#x7528;&#x6CD5;&#x5F88;&#x7B80;&#x5355;&#xFF1A;<pre data-role="codeBlock" data-info="go" class="language-go"><span class="token comment">// &#x5728;&#x51FD;&#x6570;&#x524D;&#x9762;&#x52A0;go&#x5173;&#x952E;&#x5B57;</span>
<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">go</span> <span class="token function">myFunction1</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token keyword">go</span> <span class="token function">myFunction2</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token comment">// ....</span>
<span class="token punctuation">}</span>
</pre></li>
</ul>
<p>Goroutines&#x662F;Go&#x8BED;&#x8A00;&#x4E2D;&#x7684;&#x57FA;&#x672C;&#x5E76;&#x53D1;&#x5355;&#x4F4D;&#xFF0C;&#x4E0A;&#x9762;&#x4F8B;&#x5B50;&#x4E2D;myFunction1&#xFF0C;myFunction2&#x5C06;&#x4E0E;main&#x5E76;&#x53D1;&#x6267;&#x884C;&#x3002;<br>
&#x5F53;&#x7136;&#xFF0C;&#x548C;&#x5E76;&#x53D1;&#x76F8;&#x5173;&#x8FD8;&#x6709;Channels&#x3001;Mutex&#x7B49;&#x6982;&#x5FF5;&#x6B64;&#x5904;&#x4E0D;&#x518D;&#x4E00;&#x4E00;&#x5C55;&#x5F00;&#x3002;</p>
<blockquote>
<p>&#x5728;&#x6709;&#x4E9B;&#x6587;&#x7AE0;&#x4E2D;&#x5C06;Goroutines&#x7FFB;&#x8BD1;&#x4E3A;&#x534F;&#x7A0B;&#xFF0C;&#x4F46;Go&#x8BED;&#x8A00;&#x4F5C;&#x8005;Rob Pike&#x5426;&#x8BA4;&#x4E86;&#xFF08;Goroutines = &#x534F;&#x7A0B;&#xFF09;&#x8FD9;&#x4E00;&#x8BF4;&#x6CD5;</p>
</blockquote>
<hr>
<h2 class="mume-header" id="%E9%99%84%E5%BD%95">&#x9644;&#x5F55;</h2>

<h4 class="mume-header" id="%E5%85%B3%E4%BA%8E%E5%88%86%E5%8F%B7">&#x5173;&#x4E8E;&#x5206;&#x53F7;</h4>

<p>&#x56E0;&#x4E3A;&#x53EF;&#x4EE5;&#x7701;&#x7565;&#x5206;&#x53F7;&#xFF0C;&#x6240;&#x4EE5;&#x5199;&#x4EE3;&#x7801;&#x65F6;&#x8FD8;&#x662F;&#x8001;&#x5B9E;&#x70B9;&#x597D;&#xFF0C;&#x592A;&#x6709;&#x7279;&#x8272;&#x7684;&#x4EE3;&#x7801;&#x4F1A;&#x7F16;&#x8BD1;&#x4E0D;&#x4E86;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="go" class="language-go">  b <span class="token operator">:=</span> <span class="token boolean">true</span>  
  <span class="token comment">// &#x6B63;&#x5E38;&#x6267;&#x884C;  </span>
  <span class="token keyword">if</span> b <span class="token punctuation">{</span>  
  	fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;b is true&quot;</span><span class="token punctuation">)</span>  
  <span class="token punctuation">}</span>  
  <span class="token comment">// &#x62A5;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;  </span>
  <span class="token keyword">if</span> b  
  <span class="token punctuation">{</span>  
  	fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;b is true&quot;</span><span class="token punctuation">)</span>  
  <span class="token punctuation">}</span>  

  <span class="token keyword">var</span> n <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">1</span>  
  <span class="token keyword">var</span> m <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">2</span>  
  <span class="token comment">// &#x6B63;&#x5E38;&#x6267;&#x884C;  </span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>n <span class="token operator">+</span> m<span class="token punctuation">)</span>  

  <span class="token comment">// &#x6B63;&#x5E38;&#x6267;&#x884C;  </span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>n <span class="token operator">+</span>  
  	m<span class="token punctuation">)</span>  

  <span class="token comment">// &#x62A5;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;	</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>n  
    <span class="token operator">+</span> m<span class="token punctuation">)</span>  

<span class="token comment">// &#x6B63;&#x5E38;&#x6267;&#x884C;</span>
<span class="token function">testFunction</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span>

<span class="token comment">// &#x6B63;&#x5E38;&#x6267;&#x884C;</span>
<span class="token function">testFunction</span><span class="token punctuation">(</span>
  <span class="token number">1</span><span class="token punctuation">,</span> 
  <span class="token number">2</span><span class="token punctuation">)</span>

<span class="token comment">// &#x62A5;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;	</span>
<span class="token function">testFunction</span><span class="token punctuation">(</span>
  <span class="token number">1</span><span class="token punctuation">,</span>
  <span class="token number">2</span>
  <span class="token punctuation">)</span>

<span class="token comment">// &#x5982;&#x679C;&#x786E;&#x5B9E;&#x60F3;&#x540E;&#x9762;&#x7684;&#x5C0F;&#x62EC;&#x53F7;&#x72EC;&#x81EA;&#x5360;&#x884C;&#xFF0C;&#x53EF;&#x4EE5;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x540E;&#x9762;&#x52A0;&#x4E2A;&#x9017;&#x53F7;</span>
<span class="token function">testFunction</span><span class="token punctuation">(</span>
  <span class="token number">1</span><span class="token punctuation">,</span>
  <span class="token number">2</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span>
</pre><p>&#x8FD9;&#x4E5F;&#x662F;Go&#x8BED;&#x8A00;&#x7684;&#x4E00;&#x4E2A;&#x597D;&#x5904;&#xFF0C;&#x975E;&#x6CD5;&#x7684;&#x5206;&#x53F7;&#x4F7F;&#x7528;&#x65B9;&#x5F0F;&#x4E0D;&#x4F1A;&#x88AB;&#x5E26;&#x5230;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E2D;&#x53BB;&#x3002;&#x719F;&#x6089;Javascript&#x7684;&#x670B;&#x53CB;&#x4F60;&#x61C2;&#x7684;&#x3002;</p>

      